﻿using Microsoft.AspNetCore.Mvc;
using UpperComputer.Base.SystemApplication;
using YFurion.Application;

namespace UpperComputer.Web.Entry.Controllers
{
    /// <summary>
    /// 数据字典控制器
    /// </summary>
    [ApiDescriptionSettings(ApiGroupConst.BASE_SETTING)]
    public class DataDictionaryController : AuthorizeController
    {
        private readonly IDataDictionaryService _dataDictionaryService;

        /// <summary>
        /// 数据字典控制器构造函数
        /// </summary>
        /// <param name="dataDictionaryService"></param>
        public DataDictionaryController(IDataDictionaryService dataDictionaryService)
        {
            _dataDictionaryService = dataDictionaryService;
        }

        /// <summary>
        /// 获取树形数据字典
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<List<DataDictionaryResultDto>> Get([FromQuery]DataDictionaryResultRequestDto input)
        {
            List<DataDictionaryResultDto> output = await _dataDictionaryService.GetDataDictionarys(input);
            return output;
        }

        /// <summary>
        /// 根据id获取单条数据字典
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<DataDictionaryResultDto> Get(long id)
        {
            DataDictionaryResultDto output = await _dataDictionaryService.Get(id);
            return output;
        }

        /// <summary>
        /// 新增数据字典
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<DataDictionaryResultDto> Post(DataDictionaryDto input)
        {
            DataDictionaryResultDto output = await _dataDictionaryService.Post(input);
            return output;
        }

        /// <summary>
        /// 修改数据字典
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<DataDictionaryResultDto> Put(DataDictionaryDto input)
        {
            DataDictionaryResultDto output = await _dataDictionaryService.Put(input);
            return output;
        }

        /// <summary>
        /// 根据id删除数据字典
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<EntityDto> Delete(long id)
        {
            await _dataDictionaryService.Delete(id);
            return new EntityDto { Id = id };
        }
    }
}
